package com.m3839.sdk.anti.bean;

import android.os.Parcel;
import android.os.Parcelable;

import com.m3839.sdk.anti.constant.AntiConstant;
import com.m3839.sdk.common.base.BaseBean;

import org.json.JSONObject;

/**
 * Description:LabelBean
 *
 * @author 陈宝阳
 * @create 2020/1/14 17: 08
 */
public class LabelBean extends BaseBean<LabelBean> implements Parcelable {

  public boolean show;
  public String name;
  public String func;

  public LabelBean(){}

  public LabelBean(JSONObject jsonObject) {
    parseBean(jsonObject);
  }

  public LabelBean(boolean show, String name, String func) {
    this.show = show;
    this.name = name;
    this.func = func;
  }

  protected LabelBean(Parcel in) {
    show = in.readByte() != 0;
    name = in.readString();
    func = in.readString();
  }

  @Override
  public void writeToParcel(Parcel dest, int flags) {
    dest.writeByte((byte) (show ? 1 : 0));
    dest.writeString(name);
    dest.writeString(func);
  }

  @Override
  public int describeContents() {
    return 0;
  }

  public static final Creator<LabelBean> CREATOR = new Creator<LabelBean>() {
    @Override
    public LabelBean createFromParcel(Parcel in) {
      return new LabelBean(in);
    }

    @Override
    public LabelBean[] newArray(int size) {
      return new LabelBean[size];
    }
  };

  @Override
  public LabelBean parseBean(JSONObject jsonObject) {
    if(jsonObject == null) {
      return null;
    }
    show = jsonObject.optBoolean(AntiConstant.KEY_SHOW);
    name = jsonObject.optString(AntiConstant.KEY_NAME);
    func = jsonObject.optString(AntiConstant.KEY_FUNC);
    return this;
  }
}
